const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(port, () => {
  console.log(`Server is running at http://localhost:${port}`);
});
app.get('/products', (req, res) => {
    // 假设这是从数据库获取的数据
    const products = [
      { id: 1, name: 'Product 1', price: 99 },
      { id: 2, name: 'Product 2', price: 199 },
    ];
    
    res.json(products);
  });
  app.get('/product/:id', (req, res) => {
    const productId = req.params.id;
    // 这里应该是从数据库根据ID查询商品
    const product = { id: productId, name: `Product ${productId}`, price: productId * 100 };
    
    if (!product) return res.status(404).send('Product not found');
    
    res.json(product);
  });